/**
 * 财务自动化，进度统计-数据组装
 */

import map from '@/components/map';
import axios from 'axios';

export default {
    getData() {
        return axios.post('/financeStatusStatistics').then(res => {
            let percent;
            let number;
            const total = res.data.total;
            const financeStatus = res.data.financeStatus;
            map.accountStatusList.forEach(item => {
                if (financeStatus[item.value] === undefined) {
                    financeStatus[item.value] = 0;
                }
            });

            const result = {
                left: [],
                right: []
            };

            // 财务自动化
            result.left.push({
                title: '财务自动化',
                percent: 100,
                number: total
            });
            // 财务完成
            number = financeStatus['10'];
            percent = total > 0 ? Number.parseInt((number / total) * 10000) / 100 : 100;
            result.left.push({
                title: '财务完成',
                percent,
                number
            });

            // 信息上传
            number = financeStatus['1'] + financeStatus['101'] + financeStatus['2'];
            percent = total > 0 ? Math.round((number / total) * 10000) / 100 : 100;
            result.right.push({
                title: '信息上传',
                percent,
                number,
                childrenData: [
                    {
                        title: '待上传资料',
                        value: financeStatus['1']
                    },
                    {
                        title: '票据处理中',
                        value: financeStatus['101']
                    },
                    {
                        title: '待客户上传',
                        value: financeStatus['2']
                    }
                ]
            });
            // 信息核对
            number = financeStatus['3'] + financeStatus['4'] + financeStatus['5'] + financeStatus['6'];
            percent = total > 0 ? Math.round((number / total) * 10000) / 100 : 100;
            result.right.push({
                title: '信息核对',
                percent,
                number,
                childrenData: [
                    {
                        title: '待核对',
                        value: financeStatus['3']
                    },
                    {
                        title: '核对中',
                        value: financeStatus['4']
                    },
                    {
                        title: '票据异常',
                        value: financeStatus['5']
                    },
                    {
                        title: '尚未抄报税',
                        value: financeStatus['6']
                    }
                ]
            });
            // 智能做账
            number = financeStatus['7'] + financeStatus['8'] + financeStatus['9'] + financeStatus['10'];
            percent = total > 0 ? Math.round(((number / total) * 10000)) / 100 : 100;
            result.right.push({
                title: '智能做账',
                percent,
                number,
                childrenData: [
                    {
                        title: '做账中',
                        value: financeStatus['7']
                    },
                    {
                        title: '待客户完善',
                        value: financeStatus['8']
                    },
                    {
                        title: '待确认',
                        value: financeStatus['9']
                    },
                    {
                        title: '财务完成',
                        value: financeStatus['10']
                    }
                ]
            });

            return result;
        });
    }
};
